package com.ruoyi.alarm.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.alarm.domain.AlarmTotal;
import com.ruoyi.alarm.service.IAlarmTotalService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报警统计信息Controller
 * 
 * @author ruoyi
 * @date 2023-01-04
 */
@Controller
@RequestMapping("/alarm/total")
public class AlarmTotalController extends BaseController
{
    private String prefix = "alarm/total";

    @Autowired
    private IAlarmTotalService alarmTotalService;

    @RequiresPermissions("alarm:total:view")
    @GetMapping()
    public String total()
    {
        return prefix + "/total";
    }

    /**
     * 查询报警统计信息列表
     */
    @RequiresPermissions("alarm:total:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AlarmTotal alarmTotal)
    {
        startPage();
        List<AlarmTotal> list = alarmTotalService.selectAlarmTotalList(alarmTotal);
        return getDataTable(list);
    }

    /**
     * 导出报警统计信息列表
     */
    @RequiresPermissions("alarm:total:export")
    @Log(title = "报警统计信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AlarmTotal alarmTotal)
    {
        List<AlarmTotal> list = alarmTotalService.selectAlarmTotalList(alarmTotal);
        ExcelUtil<AlarmTotal> util = new ExcelUtil<AlarmTotal>(AlarmTotal.class);
        return util.exportExcel(list, "报警统计信息数据");
    }

    /**
     * 新增报警统计信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报警统计信息
     */
    @RequiresPermissions("alarm:total:add")
    @Log(title = "报警统计信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AlarmTotal alarmTotal)
    {
        return toAjax(alarmTotalService.insertAlarmTotal(alarmTotal));
    }

    /**
     * 修改报警统计信息
     */
    @RequiresPermissions("alarm:total:edit")
    @GetMapping("/edit/{deviceId}")
    public String edit(@PathVariable("deviceId") String deviceId, ModelMap mmap)
    {
        AlarmTotal alarmTotal = alarmTotalService.selectAlarmTotalByDeviceId(deviceId);
        mmap.put("alarmTotal", alarmTotal);
        return prefix + "/edit";
    }

    /**
     * 修改保存报警统计信息
     */
    @RequiresPermissions("alarm:total:edit")
    @Log(title = "报警统计信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AlarmTotal alarmTotal)
    {
        return toAjax(alarmTotalService.updateAlarmTotal(alarmTotal));
    }

    /**
     * 删除报警统计信息
     */
    @RequiresPermissions("alarm:total:remove")
    @Log(title = "报警统计信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(alarmTotalService.deleteAlarmTotalByDeviceIds(ids));
    }
}
